// pages/order/pay/index.js
import {
    request
} from "../../../request/index.js";
var redis = require('../../../utils/redis.js').default;
Page({
    data: {
        order:[]
    },

    onLoad(options) {
        const {
            orderSn
        } = options;
        console.log(orderSn);
        this.getOrderByOrderSn(orderSn);
    },


    async getOrderByOrderSn(orderSn) {
        const token = redis.get("token");
        if (!token) {
            wx.navigateTo({
                url: '/page/login/index'
            });
            return;
        }
        const res = await request({
            url: "/orders/getOrderByOrderSn",
            data: {
                orderSn
            }
        });
        this.setData({
            order: res.data.data
        })
    },
    async continuePay() {
        let orderSn = this.data.order.orderSn;
        const res = await request({
            url: "/pays/continuePay",
            method: "POST",
            data: orderSn
        });
        if(res.data.code === 200) {
             wx.showToast({
                title: '支付成功'
            });
            setTimeout(function () {
                wx.navigateBack({
                    delta: 1,
                })
            }, 500)
        } else {
            wx.showToast({
                title: '支付失败'
            });
        }
    }
})